import { cookies, headers } from "next/headers";
// import Header from "./components/Header";

// import Main from "./_main";
import { getResumeDetail, getTemplateById, validResume } from "@/service";
import { PersonalDetailStoreProvider } from "@/src/providers/personal-detail-store-provider";
import { ContentStoreProvider } from "@/src/providers/content-store-provider";
import { CustomizationStoreProvider } from "@/src/providers/customization-store-provider";
import AuthProvider from "@/app/components/AuthProvider";
import Main from "@/src/components/pages/content/main";
import Header from "@/src/components/pages/content/header";
import { isMobile } from "@/app/utils";
import ContentEdit from "@/src/components/pages/content/edit/contentItem/edit";
export default async function Page(props: any) {
  const cookie = cookies().get("baijie_token");
  const { searchParams } = props;
  const { id, mid, type } = searchParams;
  let data = null;
  try {
    if (id) {
      data = await getResumeDetail({ id, token: cookie?.value });
    } else {
      data = await getTemplateById({ id: mid });
    }
  } catch (e) {
    console.log(e);
  }
  return (
    <AuthProvider needLogin={data?.code === 401}>
      <PersonalDetailStoreProvider
        personalDetails={data?.data?.personalDetails}
      >
        <ContentStoreProvider content={data?.data?.content}>
          <CustomizationStoreProvider customization={data?.data?.customization}>
            <ContentEdit type={type}></ContentEdit>
          </CustomizationStoreProvider>
        </ContentStoreProvider>
      </PersonalDetailStoreProvider>
    </AuthProvider>
  );
}
